﻿// Serotonin -- easy-to-use image filters application
// https://code.google.com/p/serotonin/
//
// Copyright © Frank Nagl, 2012-2013
// admin@franknagl.de
//

using Serotonin.Helper;

namespace Serotonin.OptionsForms
{
    using Filter;
    using System;
    using System.Drawing;
    using System.Windows.Forms;        

    /// <summary>Filter specified properties form.</summary>
    public partial class ExtractOrRotateChannelsForm : Form, IOptionsForm
    {
        private readonly ExtractOrRotateChannels filter;

        /// <summary>
        /// The processor for managing the images and the image GUI panel.
        /// </summary>
        public Processor Processor { get; set; }

        /// <summary>
        /// Initializes a new instance of the 
        /// <see cref="ExtractOrRotateChannelsForm"/> class.
        /// </summary>
        /// <param name="processor">The processor.</param>
        public ExtractOrRotateChannelsForm(Processor processor)
        {
            InitializeComponent();
            filter = AOF.Init(processor, this, gbProcess,
                     new ExtractOrRotateChannels()) as ExtractOrRotateChannels;
        }

                /// <summary> Applies the specified filter in the options form. </summary>
        public void ApplyFilter()
        {
            // grayscale example
            Bitmap b = filter.Apply(Processor.OriginalImage);            
            string s = Program.L.Text[40] + Program.L.Text[89] + ": " +
                       Program.L.Text[90] + "=" + filter.Order.ToString() + "; ";
            Processor.Change(b, s); 
        }

        /// <summary>
        /// Sets the language specified string texts for the form elements.
        /// </summary>
        public void SetStrings()
        {
            // Process groupbox
            gbProcess.Text = Program.L.Text[54];
            btnProcess.Text = Program.L.Text[55];
            btnReset.Text = Program.L.Text[56];

            Options.Text = Program.L.Text[89]; // Name of filter
            tabctrlOptions.TabPages[0].Text = Program.L.Text[90]; // Channel order
        }

        private void BtnProcessClick(object sender, EventArgs e)
        {
            try
            {
                ApplyFilter();
            }
            catch (ArgumentException aex)
            {
                MessageBox.Show(aex.Message);
                BtnResetClick(sender, e);
            }
        }

        private void BtnResetClick(object sender, EventArgs e)
        {
            Processor.Reset();
        }

        private void RdRCheckedChanged(object sender, EventArgs e)
        {
            if (rdR.Checked)
            {
                filter.Order = RGBOrder.R;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdGCheckedChanged(object sender, EventArgs e)
        {
            if (rdG.Checked)
            {
                filter.Order = RGBOrder.G;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdBCheckedChanged(object sender, EventArgs e)
        {
            if (rdB.Checked)
            {
                filter.Order = RGBOrder.B;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdRgbCheckedChanged(object sender, EventArgs e)
        {
            if (rdRgb.Checked)
            {
                filter.Order = RGBOrder.RGB;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdBrgCheckedChanged(object sender, EventArgs e)
        {
            if (rdBrg.Checked)
            {
                filter.Order = RGBOrder.BRG;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdBgrCheckedChanged(object sender, EventArgs e)
        {
            if (rdBgr.Checked)
            {
                filter.Order = RGBOrder.BGR;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdGbrCheckedChanged(object sender, EventArgs e)
        {
            if (rdGbr.Checked)
            {
                filter.Order = RGBOrder.GBR;
                Processor.ApplyFilterRTP();
            }
        }

        private void RdGrbCheckedChanged(object sender, EventArgs e)
        {
            if (rdGrb.Checked)
            {
                filter.Order = RGBOrder.GRB;
                Processor.ApplyFilterRTP();
            }
        }
    }
}
